import React from 'react';
import { Empty, Table } from 'antd';
import { history } from 'umi'
import BizIcon from '@/components/BizIcon';
// import styles from './index.less';
import FormContainer from './FormContainer';

const generateRouterObj = ({ employeeCode, changeType }) => {
    if (changeType === '入职') {
        return {
            pathname: '/office/personnelManagement/onboardAndLeave/entryManage/entryEmployeeDetail',
            query: { entryPersonnelCode: employeeCode }
        };
    }
    if (changeType === '转正') {
        return { pathname: '/office/personnelManagement/onboardAndLeave/informal/detail', query: { employeeCode } };
    }
    return null;
};
/**
 * 员工档案 - 微微历程 - 入职调离记录
 */
const OnboardAndLeaveSection = ({ formData, title = '入转调离记录' }) => {
    const jump = React.useCallback(row => {
        const obj = generateRouterObj(row);
        if (!obj) {
            return;
        }
        history.push(obj);
    }, []);
    const columns = [
        {
            title: '变动类型',
            dataIndex: 'changeType',
            key: 'changeType'
        },
        {
            title: '岗位',
            dataIndex: 'dutyAlias',
            key: 'dutyAlias'
        },
        {
            title: '职位',
            dataIndex: 'post',
            key: 'post'
        },
        {
            title: '所在机构',
            dataIndex: 'organizationName',
            key: 'organizationName'
        },
        {
            title: '日期',
            dataIndex: 'vvDatetime',
            key: 'vvDatetime'
        },
        {
            title: '操作',
            key: 'action',
            width: 120,
            render: (text, record) =>
                !['机构调整', '调岗', '离职'].includes(record.changeType) && (
                    <BizIcon
                        type="chakanxiangqing"
                        style={{ cursor: 'pointer', fontSize: 20 }}
                        onClick={() => jump(record)}
                    />
                )
        }
    ];

    // render
    return (
        <FormContainer title={title} hasEditAuth={false}>
            {() =>
                formData?.length ? (
                    <Table
                        columns={columns}
                        dataSource={formData}
                        rowKey="id"
                        scroll={{ y: 1080 }}
                        // rowClassName={record => (generateRouterObj(record) ? styles.tableRowCursorPointer : '')}
                        pagination={false}
                        // onRow={record => ({
                        //     onClick: () => {
                        //         jump(record)
                        //     }
                        // })}
                    />
                ) : (
                    <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
                )
            }
        </FormContainer>
    );
};

export default OnboardAndLeaveSection;
